#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc2_r12_aux_n2_gamma2.info <<'%EOF%'
   cc2_r12_aux_n2_gamma2
   ------------
   Molecule:         N2 in D2h
   Wave Function:    CC2-R12/A/1  cc-pVDZ/cc-pVDZ
   Test Purpose:     Test properties up to second hyperpolarizabilities (cubic response):
                     - for CC2-R12 (Ansatz 1) 
                     - Check frozen core
                     - test .USEXKS option 
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc2_r12_aux_n2_gamma2.mol <<'%EOF%'
BASIS
cc-pVDZ cc-pVDZ
N2        

    2  0 3  X  Y  Z  0.10D-14
 1      7.    1
N        0.0000000000000     0.0000000000000     1.0371572000000       *
 2      7.    1
N        0.0000000000000     0.0000000000000     1.0371572000000       *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc2_r12_aux_n2_gamma2.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
*MOLBAS
.R12AUX
**INTEGRALS
.R12
.DIPLEN
.THETA
**WAVE FUNCTIONS
.CC
*SCF INPUT
.THRESHOLD
 1D-10
*ORBITALS
.MOSTART
 H1DIAG
*CC INPUT
.CC2
.PRINT
 3
.FREEZE
 2 0
.THRENR
 1.0D-14
.THRLEQ
 1.0D-12
.MAX IT
 100
*CCFOP
.NONREL
.DIPMOM
.QUADRU
*CCLR
.AVERAG
ALPHA_ANI
LINEAR
.ASYMSD
*CCQR
.AVERAG
HYPERPOL
.NOBMAT
*CCCR
.AVERAG
GAMMA_ISO
LINEAR
.USEXKS
*R12 INP
.CC2
 1A
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc2_r12_aux_n2_gamma2.check
cat >>cc2_r12_aux_n2_gamma2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi


#           Total SCF   energy:                  -108.9541307667
#           Total MP2-R12/A energy:              -109.3671238978
#           Total CC2-R12/A energy:              -109.3693042691
#
#                   Total Molecular quadrupole moment
#                   ---------------------------------
#                   X              Y              Z
#              Column   1     Column   2     Column   3
#      1       0.57942058     0.00000000     0.00000000
#      2       0.00000000     0.57942058     0.00000000
#      3       0.00000000     0.00000000    -1.15884115
#
#
#      +--------------------------------------------------------------+
#      !      FINAL CC2 RESULTS FOR THE SECOND-ORDER PROPERTIES       !
#      +--------------------------------------------------------------+
#
#  A operator                  B operator                     property
#------------------------------------------------------------------------
# ZDIPLEN  (unrel.)  0.0000   ZDIPLEN  (unrel.)  0.0000      12.114587
# XDIPLEN  (unrel.)  0.0000   XDIPLEN  (unrel.)  0.0000      5.7728234
# XDIPLEN  (unrel.)    -.-    ZDIPLEN  (unrel.)    -.-          ---
#------------------------------------------------------------------------
#
#----------------------------------------------------------------------------+
#           FINAL CC2 RESULTS FOR THE SECOND HYPERPOLARIZABILITIES           !
#----------------------------------------------------------------------------+
#
# A operator        B operator        C operator        D operator           gamma
#-------------------------------------------------------------------------------------
#
# ZDIPLEN  0.0000   ZDIPLEN  0.0000   ZDIPLEN  0.0000   ZDIPLEN  0.0000     -37.554902
# ZDIPLEN  0.0000   XDIPLEN  0.0000   XDIPLEN  0.0000   ZDIPLEN  0.0000      3.2718327
# XDIPLEN  0.0000   XDIPLEN  0.0000   ZDIPLEN  0.0000   ZDIPLEN  0.0000      3.2718327
# XDIPLEN  0.0000   ZDIPLEN  0.0000   XDIPLEN  0.0000   ZDIPLEN  0.0000      3.2718327
# XDIPLEN  0.0000   ZDIPLEN  0.0000   ZDIPLEN  0.0000   XDIPLEN  0.0000      3.2718327
# ZDIPLEN  0.0000   ZDIPLEN  0.0000   XDIPLEN  0.0000   XDIPLEN  0.0000      3.2718327
# ZDIPLEN  0.0000   XDIPLEN  0.0000   ZDIPLEN  0.0000   XDIPLEN  0.0000      3.2718327
# XDIPLEN  0.0000   XDIPLEN  0.0000   XDIPLEN  0.0000   XDIPLEN  0.0000      19.943229
# XDIPLEN  0.0000   YDIPLEN  0.0000   YDIPLEN  0.0000   XDIPLEN  0.0000      6.6477429
# XDIPLEN  0.0000   XDIPLEN  0.0000   YDIPLEN  0.0000   YDIPLEN  0.0000      6.6477429
#-------------------------------------------------------------------------------------
#--------------------------------------------------------------------------

CRIT1=`$GREP "Total CC2-R12/A energy: *\-109\.369304269." $log | wc -l`
TEST[1]=`expr $CRIT1` 
CTRL[1]=2
ERROR[1]="CC2-R12/A ENERGY NOT CORRECT"

CRIT2=`$GREP "XDIPLEN .*19\.943229" $log | wc -l`
CRIT3=`$GREP "ZDIPLEN .*\-37\.554902" $log | wc -l`
CRIT4=`$GREP "XDIPLEN .*6\.6477429" $log | wc -l`
CRIT5=`$GREP "ZDIPLEN .*3\.2718327" $log | wc -l`
TEST[2]=`expr $CRIT2 + $CRIT3 + $CRIT4 + $CRIT5`
CTRL[2]=10
ERROR[2]="CC2-R12/A SECOND HYPERPOLARIZABILITY  NOT CORRECT"

CRIT6=`$GREP "\.57942058" $log | wc -l`
CRIT7=`$GREP "\-1\.15884115" $log | wc -l`
TEST[3]=`expr $CRIT6 + $CRIT7`
CTRL[3]=3
ERROR[3]="CC2-R12/A Quadrupolmoment  NOT CORRECT"

CRIT8=`$GREP "ZDIPLEN .*12\.114587" $log | wc -l`
CRIT9=`$GREP "XDIPLEN .*5.7728234" $log | wc -l`
TEST[4]=`expr $CRIT8 + $CRIT9`
CTRL[4]=2
ERROR[4]="CC2-R12/A SECOND ORDER PROPERTIES NOT CORRECT"

PASSED=1
for i in 1 2 3 4
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
